<?php
/**
 * 古今玩小程序模块微站定义
 *
 * @author 指尖团队
 * @url http://bbs.we7.cc/
 */
defined('IN_IA') or exit('Access Denied');
require IA_ROOT.'/addons/zh_gjw/inc/func/core.php';
class Zh_gjwModuleSite extends Core {

    //获取编辑的上级抖宝分类
    public function doMobileGetedbcate(){
        global $_W,$_GPC;
        $dbcate=pdo_get('zh_gjw_dbcate',array('uniacid'=>$_W['uniacid'],'id'=>$_GPC['pid']));
        echo json_encode($dbcate);
    }
    //获取添加的上级抖宝分类
    public function doMobileGetadbcate(){
        global $_W,$_GPC;
        $dbcate=pdo_get('zh_gjw_dbcate',array('uniacid'=>$_W['uniacid'],'id'=>$_GPC['id']));
        echo json_encode($dbcate);
    }
    //获取编辑的上级微拍分类
    public function doMobileGeteshotcate(){
        global $_W,$_GPC;
        $dbcate=pdo_get('zh_gjw_shotcate',array('uniacid'=>$_W['uniacid'],'id'=>$_GPC['pid']));
        echo json_encode($dbcate);
    }
    //获取添加的上级微拍分类
    public function doMobileGetashotcate(){
        global $_W,$_GPC;
        $dbcate=pdo_get('zh_gjw_shotcate',array('uniacid'=>$_W['uniacid'],'id'=>$_GPC['id']));
        echo json_encode($dbcate);
    }
    //获取编辑的上级地摊分类
    public function doMobileGetemarketcate(){
        global $_W,$_GPC;
        $dbcate=pdo_get('zh_gjw_marketcate',array('uniacid'=>$_W['uniacid'],'id'=>$_GPC['pid']));
        echo json_encode($dbcate);
    }
    //获取添加的上级地摊分类
    public function doMobileGetamarketcate(){
        global $_W,$_GPC;
        $dbcate=pdo_get('zh_gjw_marketcate',array('uniacid'=>$_W['uniacid'],'id'=>$_GPC['id']));
        echo json_encode($dbcate);
    }
    //获取编辑的上级定制分类
    public function doMobileGetepricate(){
        global $_W,$_GPC;
        $dbcate=pdo_get('zh_gjw_pricate',array('uniacid'=>$_W['uniacid'],'id'=>$_GPC['pid']));
        echo json_encode($dbcate);
    }
    //获取添加的上级定制分类
    public function doMobileGetapricate(){
        global $_W,$_GPC;
        $dbcate=pdo_get('zh_gjw_pricate',array('uniacid'=>$_W['uniacid'],'id'=>$_GPC['id']));
        echo json_encode($dbcate);
    }
    //批量删除游客
    public function doMobileDeletevisit(){
        global $_W,$_GPC;
        $res=pdo_delete("zh_gjw_visit",array('id'=>$_GPC['id']));
        if($res){
            message('删除成功！', $this->createWebUrl('visit'), 'success');
        }else{
            message('删除失败！','','error');
        }
    }
    //批量删除用户
    public function doMobileDeletereg(){
        global $_W,$_GPC;
        $res=pdo_delete("zh_gjw_register",array('id'=>$_GPC['id']));
        if($res){
            message('删除成功！', $this->createWebUrl('register'), 'success');
        }else{
            message('删除失败！','','error');
        }
    }
    //批量删除抖宝
    public function doMobileDeletedb(){
        global $_W,$_GPC;
      	for ($i=0; $i <count($_GPC['id']) ; $i++) { 
          $file=pdo_get('zh_gjw_dbpublish',array('id'=>$_GPC['id'][$i]));
          $url=str_replace('https://','',$_W['attachurl_local']);
          unlink('/www/wwwroot/'.$url.$file['videoimg']);
          unlink('/www/wwwroot/'.$url.$file['video']);
        }
        $res=pdo_delete("zh_gjw_dbpublish",array('id'=>$_GPC['id']));
        if($res){
            message('删除成功！', $this->createWebUrl('dblist'), 'success');
        }else{
            message('删除失败！','','error');
        }
    }
    //批量审核抖宝
    public function doMobileShdby(){
        global $_W,$_GPC;
        include_once IA_ROOT . '/addons/zh_gjw/cert/WxPay.Api.php';
        load()->model('account');
        load()->func('communication');
        $WxPayApi = new WxPayApi();
        $input = new WxPayRefund();
        $path_cert = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_cert_' . $_W['uniacid'] . '.pem';
        $path_key = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_key_' . $_W['uniacid'] . '.pem';
        $refund_order =pdo_get('zh_gjw_dbpublish',array('id'=>$_GPC['id']));  
          /*function getaccess_token($_W){
            $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
            $appid=$res['appid'];
            $secret=$res['appsecret'];
            $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL,$url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
            $data = curl_exec($ch);
            curl_close($ch);
            $data = json_decode($data,true);
            return $data['access_token'];
          }*/
          function set_msg($_W,$id){
              //$access_token = getaccess_token($_W);
              $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
              $user=pdo_get('zh_gjw_dbpublish',array('id'=>$id));
              $openid=pdo_get('zh_gjw_register',array('phone'=>$user['phone']));
              $formwork ='{
                  "touser": "'.$openid["openid"].'",
                  "template_id": "'.$ress["templeid"].'",
                  "form_id":"'.$user['formid'].'",
                  "data": {
                      "keyword1": {
                          "value": "'.$user['dbname'].'",
                          "color": "#173177"
                      },
                      "keyword2": {
                          "value":"抖宝审核通过",
                          "color": "#173177"
                      }
                  }  
              }';
              $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
              $ch = curl_init();
              curl_setopt($ch, CURLOPT_URL,$url);
              curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
              curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
              curl_setopt($ch, CURLOPT_POST,1);
              curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
              $data = curl_exec($ch);
              curl_close($ch);
             return $data;
          }
        for ($i=0; $i <count($_GPC['id']) ; $i++) {
          $refund_order =pdo_get('zh_gjw_dbpublish',array('id'=>$_GPC['id'][$i]));  
          if ($refund_order['pay']==1) {
            echo set_msg($_W,$_GPC['id'][$i]);
            $res=pdo_update('zh_gjw_dbpublish',array('state'=>2),array('id'=>$_GPC['id'][$i]));
            
          }
        }
    }
    //批量拒审抖宝
    public function doMobileShdbn(){
      global $_W,$_GPC;
      include_once IA_ROOT . '/addons/zh_gjw/cert/WxPay.Api.php';
      load()->model('account');
      load()->func('communication');
      $WxPayApi = new WxPayApi();
      $input = new WxPayRefund();
      $path_cert = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_cert_' . $_W['uniacid'] . '.pem';
      $path_key = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_key_' . $_W['uniacid'] . '.pem';
      // $refund_order =pdo_get('zh_gjw_dbpublish',array('id'=>$_GPC['id']));  

              /*function getaccess_token($_W){
                $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
                $appid=$res['appid'];
                $secret=$res['appsecret'];
                $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL,$url);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
                $data = curl_exec($ch);
                curl_close($ch);
                $data = json_decode($data,true);
                return $data['access_token'];
              }*/
              function set_msg($_W,$id){
                  //$access_token = getaccess_token($_W);
                  $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
                  $user=pdo_get('zh_gjw_dbpublish',array('id'=>$id));
                  $openid=pdo_get('zh_gjw_register',array('phone'=>$user['phone']));
                  $formwork ='{
                      "touser": "'.$openid["openid"].'",
                      "template_id": "'.$ress["templeid"].'",
                      "form_id":"'.$user['formid'].'",
                      "data": {
                          "keyword1": {
                              "value": "'.$user['dbname'].'",
                              "color": "#173177"
                          },
                          "keyword2": {
                              "value":"抖宝审核未通过",
                              "color": "#173177"
                          }
                      }  
                  }';
                  $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
                  $ch = curl_init();
                  curl_setopt($ch, CURLOPT_URL,$url);
                  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
                  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
                  curl_setopt($ch, CURLOPT_POST,1);
                  curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
                  $data = curl_exec($ch);
                  curl_close($ch);
                 return $data;
              }
      for ($i=0; $i <count($_GPC['id']) ; $i++) {
        $refund_order =pdo_get('zh_gjw_dbpublish',array('id'=>$_GPC['id'][$i])); 
        if (empty($refund_order['paycode'])) {
            message('发布支付未设置，所以此条未支付',$this->createWebUrl('dblist',array()),'success');
        } 
        $res_fee=$refund_order['payfee'];
        // $shotmoney =pdo_get('zh_gjw_dbmoney',array('uniacid'=>$_W['uniacid'])); 
      
        if ($refund_order['pay']==1) {
          if ($refund_order['paycode']) {
            $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
            $appid=$res['appid'];
            $key=$res['apikey'];
            $mchid=$res['mac_id'];
            $out_trade_no=$refund_order['paycode'];//商户订单号
            $fee = $res_fee * 100;
            $input->SetAppid($appid);
            $input->SetMch_id($mchid);
            $input->SetOp_user_id($mchid);
            $input->SetRefund_fee($fee);
            $input->SetTotal_fee($fee);
            $input->SetOut_refund_no($refund_order['paycode']);
            $input->SetOut_trade_no($out_trade_no);
            $result = $WxPayApi->refund($input, 6, $path_cert, $path_key, $key);

            if ($result['result_code'] == 'SUCCESS') {//退款成功
                  echo set_msg($_W,$_GPC['id'][$i]);
                  if ($refund_order['upfee']==1) {
                    pdo_update('zh_gjw_dbpublish',array('pay'=>2,'state'=>3,'upfee'=>2),array('id'=>$_GPC['id'][$i]));
                  }else{
                    pdo_update('zh_gjw_dbpublish',array('pay'=>2,'state'=>3),array('id'=>$_GPC['id'][$i]));
                  }
              }else{
                  message($result['err_code_des'],'','error');
              }
          }
        }
      }
    }

    //批量删除抖宝评论
    public function doMobileDeletedbassess(){
        global $_W,$_GPC;
        $res=pdo_delete("zh_gjw_dbassess",array('id'=>$_GPC['id']));
        if($res){
            message('删除成功！', $this->createWebUrl('dbassess'), 'success');
        }else{
            message('删除失败！','','error');
        }
    }
    //批量审核抖宝评论
    public function doMobileShdbassessy(){
        global $_W,$_GPC;
        include_once IA_ROOT . '/addons/zh_gjw/cert/WxPay.Api.php';
        load()->model('account');
        load()->func('communication');
        $WxPayApi = new WxPayApi();
        $input = new WxPayRefund();
        $path_cert = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_cert_' . $_W['uniacid'] . '.pem';
        $path_key = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_key_' . $_W['uniacid'] . '.pem';
        $refund_order =pdo_get('zh_gjw_dbassess',array('id'=>$_GPC['id'])); 
          /*function getaccess_token($_W){
            $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
            $appid=$res['appid'];
            $secret=$res['appsecret'];
            $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL,$url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
            $data = curl_exec($ch);
            curl_close($ch);
            $data = json_decode($data,true);
            return $data['access_token'];
          }*/
          function set_msg($_W,$id){
              //$access_token = getaccess_token($_W);
              $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
              $user=pdo_get('zh_gjw_dbassess',array('id'=>$id));
              $content=mb_substr($user['content'],0,3,'utf-8');
              $openid=pdo_get('zh_gjw_register',array('id'=>$user['u_id']));
              $formwork ='{
                  "touser": "'.$openid["openid"].'",
                  "template_id": "'.$ress["templeid"].'",
                  "form_id":"'.$user['formid'].'",
                  "data": {
                      "keyword1": {
                          "value": "'.$content.'...",
                          "color": "#173177"
                      },
                      "keyword2": {
                          "value":"抖宝评论审核通过",
                          "color": "#173177"
                      }
                  }  
              }';
              $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
              $ch = curl_init();
              curl_setopt($ch, CURLOPT_URL,$url);
              curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
              curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
              curl_setopt($ch, CURLOPT_POST,1);
              curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
              $data = curl_exec($ch);
              curl_close($ch);
             return $data;
          }
        for ($i=0; $i <count($_GPC['id']) ; $i++) {
            echo set_msg($_W,$_GPC['id'][$i]);
            pdo_update('zh_gjw_dbassess',array('state'=>2),array('id'=>$_GPC['id'][$i]));
        }
    }
    //批量拒审抖宝评论
    public function doMobileShdbassessn(){
      global $_W,$_GPC;
      include_once IA_ROOT . '/addons/zh_gjw/cert/WxPay.Api.php';
      load()->model('account');
      load()->func('communication');
      $WxPayApi = new WxPayApi();
      $input = new WxPayRefund();
      $path_cert = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_cert_' . $_W['uniacid'] . '.pem';
      $path_key = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_key_' . $_W['uniacid'] . '.pem';
      $refund_order =pdo_get('zh_gjw_dbassess',array('id'=>$_GPC['id']));  
      
              /*function getaccess_token($_W){
                $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
                $appid=$res['appid'];
                $secret=$res['appsecret'];
                $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL,$url);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
                $data = curl_exec($ch);
                curl_close($ch);
                $data = json_decode($data,true);
                return $data['access_token'];
              }*/
              function set_msg($_W,$id){
                  //$access_token = getaccess_token($_W);
                  $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
                  $user=pdo_get('zh_gjw_dbassess',array('id'=>$id));
                  $content=mb_substr($user['content'],0,3,'utf-8');
                  $openid=pdo_get('zh_gjw_register',array('id'=>$user['u_id']));
                  $formwork ='{
                      "touser": "'.$openid["openid"].'",
                      "template_id": "'.$ress["templeid"].'",
                      "form_id":"'.$user['formid'].'",
                      "data": {
                          "keyword1": {
                              "value": "'.$content.'...",
                              "color": "#173177"
                          },
                          "keyword2": {
                              "value":"抖宝评论审核未通过",
                              "color": "#173177"
                          }
                      }  
                  }';
                  $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
                  $ch = curl_init();
                  curl_setopt($ch, CURLOPT_URL,$url);
                  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
                  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
                  curl_setopt($ch, CURLOPT_POST,1);
                  curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
                  $data = curl_exec($ch);
                  curl_close($ch);
                 return $data;
              }
              
        for ($i=0; $i <count($_GPC['id']) ; $i++) {
            echo set_msg($_W,$_GPC['id'][$i]);
            pdo_update('zh_gjw_dbassess',array('state'=>3),array('id'=>$_GPC['id'][$i]));
        }
      
    }

    //批量删除微拍
    public function doMobileDeleteshot(){
        global $_W,$_GPC;
      	for ($i=0; $i <count($_GPC['id']) ; $i++) { 
          $file=pdo_get('zh_gjw_shotpublish',array('id'=>$_GPC['id'][$i]));
          $imgs=explode(",",$file['img']);
          $url=str_replace('https://','',$_W['attachurl_local']);
          unlink('/www/wwwroot/'.$url.$file['video']);
          for ($j=0; $j <count($imgs) ; $j++) { 
            unlink('/www/wwwroot/'.$url.$imgs[$j]);
          }
        }
        $res=pdo_delete("zh_gjw_shotpublish",array('id'=>$_GPC['id']));
        if($res){
            message('删除成功！', $this->createWebUrl('shotmanage'), 'success');
        }else{
            message('删除失败！','','error');
        }
    }

    //批量审核微拍
    public function doMobileYshot(){
        global $_W,$_GPC;
        include_once IA_ROOT . '/addons/zh_gjw/cert/WxPay.Api.php';
        load()->model('account');
        load()->func('communication');
        $WxPayApi = new WxPayApi();
        $input = new WxPayRefund();
        $path_cert = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_cert_' . $_W['uniacid'] . '.pem';
        $path_key = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_key_' . $_W['uniacid'] . '.pem';
            /*function getaccess_token($_W){
              $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
              $appid=$res['appid'];
              $secret=$res['appsecret'];
              $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
              $ch = curl_init();
              curl_setopt($ch, CURLOPT_URL,$url);
              curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
              curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
              $data = curl_exec($ch);
              curl_close($ch);
              $data = json_decode($data,true);
              return $data['access_token'];
            }*/
            function set_msg($_W,$id){
                //$access_token = getaccess_token($_W);
                $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
                $user=pdo_get('zh_gjw_shotpublish',array('id'=>$id));
                $openid=pdo_get('zh_gjw_register',array('phone'=>$user['phone']));
                $formwork ='{
                    "touser": "'.$openid["openid"].'",
                    "template_id": "'.$ress["templeid"].'",
                    "form_id":"'.$user['formid'].'",
                    "data": {
                        "keyword1": {
                            "value": "'.$user['title'].'",
                            "color": "#173177"
                        },
                        "keyword2": {
                            "value":"微拍审核通过",
                            "color": "#173177"
                        }
                    }  
                }';
                $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL,$url);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
                curl_setopt($ch, CURLOPT_POST,1);
                curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
                $data = curl_exec($ch);
                curl_close($ch);
               return $data;
            }
        for ($i=0; $i <count($_GPC['id']) ; $i++) {
          $refund_order =pdo_get('zh_gjw_shotpublish',array('id'=>$_GPC['id'][$i]));  
          if ($refund_order['pay']==1) {
            echo set_msg($_W,$_GPC['id'][$i]);
            $res=pdo_update('zh_gjw_shotpublish',array('state'=>2,'shtime'=>date('Y-m-d H:i:s',time())),array('id'=>$_GPC['id'][$i]));
            
          }
        }
    }
    //批量拒审微拍
    public function doMobileNshot(){
      global $_W,$_GPC;
      include_once IA_ROOT . '/addons/zh_gjw/cert/WxPay.Api.php';
      load()->model('account');
      load()->func('communication');
      $WxPayApi = new WxPayApi();
      $input = new WxPayRefund();
      $path_cert = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_cert_' . $_W['uniacid'] . '.pem';
      $path_key = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_key_' . $_W['uniacid'] . '.pem';
                /*function getaccess_token($_W){
                  $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
                  $appid=$res['appid'];
                  $secret=$res['appsecret'];
                  $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
                  $ch = curl_init();
                  curl_setopt($ch, CURLOPT_URL,$url);
                  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
                  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
                  $data = curl_exec($ch);
                  curl_close($ch);
                  $data = json_decode($data,true);
                  return $data['access_token'];
                }*/
                function set_msg($_W,$id){
                    //$access_token = getaccess_token($_W);
                    $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
                    $user=pdo_get('zh_gjw_shotpublish',array('id'=>$id));
                    $openid=pdo_get('zh_gjw_register',array('phone'=>$user['phone']));
                    $formwork ='{
                        "touser": "'.$openid["openid"].'",
                        "template_id": "'.$ress["templeid"].'",
                        "form_id":"'.$user['formid'].'",
                        "data": {
                            "keyword1": {
                                "value": "'.$user['title'].'",
                                "color": "#173177"
                            },
                            "keyword2": {
                                "value":"微拍审核未通过",
                                "color": "#173177"
                            }
                        }  
                    }';
                    $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
                    $ch = curl_init();
                    curl_setopt($ch, CURLOPT_URL,$url);
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
                    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
                    curl_setopt($ch, CURLOPT_POST,1);
                    curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
                    $data = curl_exec($ch);
                    curl_close($ch);
                   return $data;
                }
      for ($i=0; $i <count($_GPC['id']) ; $i++) {
        $refund_order =pdo_get('zh_gjw_shotpublish',array('id'=>$_GPC['id'][$i])); 
        if (empty($refund_order['paycode'])) {
            message('发布支付未设置，所以此条未支付',$this->createWebUrl('shotmanage',array()),'success');
        } 
        $res_fee=$refund_order['payfee'];
        $shotmoney =pdo_get('zh_gjw_shotmoney',array('uniacid'=>$_W['uniacid'])); 
        
        if ($refund_order['pay']==1) {
            if ($refund_order['paycode']) {
              $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
              $appid=$res['appid'];
              $key=$res['apikey'];
              $mchid=$res['mac_id'];
              $out_trade_no=$refund_order['paycode'];//商户订单号
              $fee = $res_fee * 100;
              $input->SetAppid($appid);
              $input->SetMch_id($mchid);
              $input->SetOp_user_id($mchid);
              $input->SetRefund_fee($fee);
              $input->SetTotal_fee($fee);
              $input->SetOut_refund_no($refund_order['paycode']);
              $input->SetOut_trade_no($out_trade_no);
              $result = $WxPayApi->refund($input, 6, $path_cert, $path_key, $key);

              if ($result['result_code'] == 'SUCCESS') {//退款成功
                
                echo set_msg($_W,$_GPC['id'][$i]);
                if ($refund_order['upfee']==1) {
                  pdo_update('zh_gjw_shotpublish',array('pay'=>2,'state'=>3,'upfee'=>2),array('id'=>$_GPC['id'][$i]));
                }else{
                  pdo_update('zh_gjw_shotpublish',array('pay'=>2,'state'=>3),array('id'=>$_GPC['id'][$i]));
                }
                  
              }else{
                  message($result['err_code_des'],'','error');
              }
            }
        }
      }
    }
    //批量删除定制
    public function doMobileDeleteprinote(){
        global $_W,$_GPC;
      	for ($i=0; $i <count($_GPC['id']) ; $i++) { 
          $file=pdo_get('zh_gjw_pripublish',array('id'=>$_GPC['id'][$i]));
          $imgs=explode(",",$file['img']);
          $url=str_replace('https://','',$_W['attachurl_local']);
          for ($j=0; $j <count($imgs) ; $j++) { 
            unlink('/www/wwwroot/'.$url.$imgs[$j]);
          }
        }
        $res=pdo_delete("zh_gjw_pripublish",array('id'=>$_GPC['id']));
        if($res){
            message('删除成功！', $this->createWebUrl('primanage'), 'success');
        }else{
            message('删除失败！','','error');
        }
    }
    //批量审核定制帖
    public function doMobileYprinote(){
        global $_W,$_GPC;
        include_once IA_ROOT . '/addons/zh_gjw/cert/WxPay.Api.php';
        load()->model('account');
        load()->func('communication');
        $WxPayApi = new WxPayApi();
        $input = new WxPayRefund();
        $path_cert = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_cert_' . $_W['uniacid'] . '.pem';
        $path_key = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_key_' . $_W['uniacid'] . '.pem';
                /*function getaccess_token($_W){
                  $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
                  $appid=$res['appid'];
                  $secret=$res['appsecret'];
                  $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
                  $ch = curl_init();
                  curl_setopt($ch, CURLOPT_URL,$url);
                  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
                  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
                  $data = curl_exec($ch);
                  curl_close($ch);
                  $data = json_decode($data,true);
                  return $data['access_token'];
                }*/
                function set_msg($_W,$id){
                    //$access_token = getaccess_token($_W);
                    $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
                    $openid=pdo_get('zh_gjw_pripublish',array('id'=>$id));
                    $formwork ='{
                        "touser": "'.$openid["openid"].'",
                        "template_id": "'.$ress["templeid"].'",
                        "form_id":"'.$openid['formid'].'",
                        "data": {
                            "keyword1": {
                                "value": "'.$openid['title'].'",
                                "color": "#173177"
                            },
                            "keyword2": {
                                "value":"定制审核通过",
                                "color": "#173177"
                            }
                        }  
                    }';
                    $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
                    $ch = curl_init();
                    curl_setopt($ch, CURLOPT_URL,$url);
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
                    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
                    curl_setopt($ch, CURLOPT_POST,1);
                    curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
                    $data = curl_exec($ch);
                    curl_close($ch);
                   return $data;
                }
        for ($i=0; $i <count($_GPC['id']) ; $i++) { 
          $refund_order =pdo_get('zh_gjw_pripublish',array('id'=>$_GPC['id'][$i],'state'=>1));  
          if ($refund_order['pay']==2) {
              
                
                echo set_msg($_W,$_GPC['id'][$i]);
                pdo_update('zh_gjw_pripublish',array('state'=>2),array('id'=>$_GPC['id'][$i]));
                
          }
        }
    }

    //批量拒审定制帖
    public function doMobileNprinote(){
      global $_W,$_GPC;
      include_once IA_ROOT . '/addons/zh_gjw/cert/WxPay.Api.php';
      load()->model('account');
      load()->func('communication');
      $WxPayApi = new WxPayApi();
      $input = new WxPayRefund();
      $path_cert = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_cert_' . $_W['uniacid'] . '.pem';
      $path_key = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_key_' . $_W['uniacid'] . '.pem';
            /*function getaccess_token($_W){
                $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
                $appid=$res['appid'];
                $secret=$res['appsecret'];
                $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL,$url);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
                $data = curl_exec($ch);
                curl_close($ch);
                $data = json_decode($data,true);
                return $data['access_token'];
              }*/
              function set_msg($_W,$id){
                  //$access_token = getaccess_token($_W);
                  $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
                  $openid=pdo_get('zh_gjw_pripublish',array('id'=>$id));
                  $formwork ='{
                      "touser": "'.$openid["openid"].'",
                      "template_id": "'.$ress["templeid"].'",
                      "form_id":"'.$openid['formid'].'",
                      "data": {
                          "keyword1": {
                              "value": "'.$openid['title'].'",
                              "color": "#173177"
                          },
                          "keyword2": {
                              "value":"定制审核未通过",
                              "color": "#173177"
                          }
                      }  
                  }';
                  $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
                  $ch = curl_init();
                  curl_setopt($ch, CURLOPT_URL,$url);
                  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
                  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
                  curl_setopt($ch, CURLOPT_POST,1);
                  curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
                  $data = curl_exec($ch);
                  curl_close($ch);
                 return $data;
              }
      for ($i=0; $i <count($_GPC['id']) ; $i++) { 
        $refund_order =pdo_get('zh_gjw_pripublish',array('id'=>$_GPC['id'][$i],'state'=>1)); 
        $cusid =pdo_get('zh_gjw_cusmanage',array('phone'=>$refund_order['phone']));   
        $primoney =pdo_get('zh_gjw_primoney',array('uniacid'=>$_W['uniacid'])); 
        if ($cusid) {
          if ($refund_order['pay']==2) {
            $res_fee =$primoney['publishfee'];
            if ($refund_order['upfee']==1) {
            $res_fee =$res_fee+$primoney['upfee'];
            }
            if ($refund_order['topfee']==1) {
              $res_fee =$res_fee+$primoney['topfee'];
            }
            if ($refund_order['paycode']) { 
              $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
              $appid=$res['appid'];
              $key=$res['apikey'];
              $mchid=$res['mac_id'];
              $out_trade_no=$refund_order['paycode'];//商户订单号
              $fee = $res_fee*100;
               //var_dump($fee);die;
              $input->SetAppid($appid);
              $input->SetMch_id($mchid);
              $input->SetOp_user_id($mchid);
              $input->SetRefund_fee($fee);
              $input->SetTotal_fee($fee);
              $input->SetOut_refund_no($refund_order['paycode']);
              $input->SetOut_trade_no($out_trade_no);
              $result = $WxPayApi->refund($input, 6, $path_cert, $path_key, $key);
              
              if ($result['result_code'] == 'SUCCESS') {//退款成功
                
                  echo set_msg($_W,$_GPC['id'][$i]);
                  pdo_update('zh_gjw_pripublish',array('state'=>3,'pay'=>3),array('id'=>$_GPC['id'][$i]));
                  
              }else{
                  message($result['err_code_des'],'','error');
              }
            }
          }
        }else{
                  echo set_msg($_W,$_GPC['id'][$i]);
                  pdo_update('zh_gjw_pripublish',array('state'=>3,'pay'=>3),array('id'=>$_GPC['id'][$i]));
        }
      }
    }

    //批量删除商家认证
    public function doMobileDeletecus(){
        global $_W,$_GPC;
        for ($i=0; $i <count($_GPC['id']) ; $i++) { 
          $user=pdo_get('zh_gjw_cusmanage',array('id'=>$_GPC['id'][$i])); 
          $uid=pdo_get('users',array('username'=>$user['phone']));
          pdo_delete('users',array('username'=>$user['phone']));
          pdo_delete('uni_account_users',array('uid'=>$uid['uid']));
          pdo_delete('users_permission',array('uid'=>$uid['uid']));
          
          $imgs=explode(",",$user['cardimg']);
          $url=str_replace('https://','',$_W['attachurl_local']);
          unlink('/www/wwwroot/'.$url.$user['liceneimg']);
          unlink('/www/wwwroot/'.$url.$user['bannerimg']);
          for ($j=0; $j <count($imgs) ; $j++) { 
            unlink('/www/wwwroot/'.$url.$imgs[$j]);
          }
        }
        $res=pdo_delete("zh_gjw_cusmanage",array('id'=>$_GPC['id']));
        if($res){
            message('删除成功！', $this->createWebUrl('cusmanage'), 'success');
        }else{
            message('删除失败！','','error');
        }
    }
    //批量审核商家认证
    public function doMobileShcusy(){
        global $_W,$_GPC;
        include_once IA_ROOT . '/addons/zh_gjw/cert/WxPay.Api.php';
        load()->model('account');
        load()->func('communication');
        $WxPayApi = new WxPayApi();
        $input = new WxPayRefund();
        $path_cert = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_cert_' . $_W['uniacid'] . '.pem';
        $path_key = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_key_' . $_W['uniacid'] . '.pem';
          /*function getaccess_token($_W){
            $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
            $appid=$res['appid'];
            $secret=$res['appsecret'];
            $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL,$url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
            $data = curl_exec($ch);
            curl_close($ch);
            $data = json_decode($data,true);
            return $data['access_token'];
          }*/
          function set_msg($_W,$id){
              //$access_token = getaccess_token($_W);
              $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
              $user=pdo_get('zh_gjw_cusmanage',array('id'=>$id));
              $formwork ='{
                  "touser": "'.$user["openid"].'",
                  "template_id": "'.$ress["templeid"].'",
                  "form_id":"'.$user['formid'].'",
                  "data": {
                      "keyword1": {
                          "value": "'.$user['cusname'].'",
                          "color": "#173177"
                      },
                      "keyword2": {
                          "value":"商家认证审核通过",
                          "color": "#173177"
                      }
                  }  
              }';
              $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
              $ch = curl_init();
              curl_setopt($ch, CURLOPT_URL,$url);
              curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
              curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
              curl_setopt($ch, CURLOPT_POST,1);
              curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
              $data = curl_exec($ch);
              curl_close($ch);
             return $data;
          }
        for ($i=0; $i <count($_GPC['id']) ; $i++) { 
          $refund_order =pdo_get('zh_gjw_cusmanage',array('id'=>$_GPC['id'][$i]));  
          
          echo set_msg($_W,$_GPC['id'][$i]);
          $user['username']=$refund_order['phone'];
          $user['password']=$refund_order['password'];
          $user['salt'];
          $uid = user_register($user,null);
          if ($uid > 0) {
              unset($user['password']);
              $data = array(
                  'uniacid' => $_W['uniacid'],
                  'uid' => $uid,
                  'role' => 'operator',
              );
              $exists = pdo_fetch("SELECT * FROM " . tablename('uni_account_users') . " WHERE uid = :uid AND uniacid = :uniacid", array(':uniacid' => $_W['uniacid'], ':uid' => $uid));
              if (empty($exists)) {
                  pdo_insert('uni_account_users', $data);
              }
              pdo_insert('users_permission', array(
                  'uid' => $uid,
                  'uniacid' => $_W['uniacid'],
                  'url' => '',
                  'type' => 'zh_gjw',
              ));
          }
          pdo_update('zh_gjw_cusmanage',array('sh'=>2),array('id'=>$_GPC['id'][$i]));
        }
          
    }
    //批量拒审商家认证
    public function doMobileShcusn(){
      global $_W,$_GPC;
      include_once IA_ROOT . '/addons/zh_gjw/cert/WxPay.Api.php';
      load()->model('account');
      load()->func('communication');
      $WxPayApi = new WxPayApi();
      $input = new WxPayRefund();
      $path_cert = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_cert_' . $_W['uniacid'] . '.pem';
      $path_key = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_key_' . $_W['uniacid'] . '.pem';
        /*function getaccess_token($_W){
          $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
          $appid=$res['appid'];
          $secret=$res['appsecret'];
          $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL,$url);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
          curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
          $data = curl_exec($ch);
          curl_close($ch);
          $data = json_decode($data,true);
          return $data['access_token'];
        }*/
        function set_msg($_W,$_GPC){
            //$access_token = getaccess_token($_W);
            $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
            $user=pdo_get('zh_gjw_cusmanage',array('id'=>$_GPC['id'][$i]));
            $formwork ='{
                "touser": "'.$user["openid"].'",
                "template_id": "'.$ress["templeid"].'",
                "form_id":"'.$user['formid'].'",
                "data": {
                    "keyword1": {
                        "value": "'.$user['cusname'].'",
                        "color": "#173177"
                    },
                    "keyword2": {
                        "value":"商家认证审核未通过",
                        "color": "#173177"
                    }
                }  
            }';
            $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL,$url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
            curl_setopt($ch, CURLOPT_POST,1);
            curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
            $data = curl_exec($ch);
            curl_close($ch);
           return $data;
        }
      for ($i=0; $i <count($_GPC['id']) ; $i++) { 
        $refund_order =pdo_get('zh_gjw_cusmanage',array('id'=>$_GPC['id'][$i])); 
        
        echo set_msg($_W,$_GPC);
        pdo_update('zh_gjw_cusmanage',array('sh'=>3,'pay'=>2),array('id'=>$_GPC['id'][$i]));
      }
    }
    //批量删除地摊
    public function doMobileDeletemarket(){
        global $_W,$_GPC;
        for ($i=0; $i <count($_GPC['id']) ; $i++) { 
          $file=pdo_get('zh_gjw_marketpublish',array('id'=>$_GPC['id'][$i]));
          $imgs=explode(",",$file['img']);
          $url=str_replace('https://','',$_W['attachurl_local']);
          unlink('/www/wwwroot/'.$url.$file['video']);
          for ($j=0; $j <count($imgs) ; $j++) { 
            unlink('/www/wwwroot/'.$url.$imgs[$j]);
          }
        }
        $res=pdo_delete("zh_gjw_marketpublish",array('id'=>$_GPC['id']));
        if($res){
            message('删除成功！', $this->createWebUrl('marketmanage'), 'success');
        }else{
            message('删除失败！','','error');
        }
    }
    //批量审核地摊
    public function doMobileMarkety(){
        global $_W,$_GPC;
        include_once IA_ROOT . '/addons/zh_gjw/cert/WxPay.Api.php';
        load()->model('account');
        load()->func('communication');
        $WxPayApi = new WxPayApi();
        $input = new WxPayRefund();
        $path_cert = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_cert_' . $_W['uniacid'] . '.pem';
        $path_key = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_key_' . $_W['uniacid'] . '.pem';
            /*function getaccess_token($_W){
              $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
              $appid=$res['appid'];
              $secret=$res['appsecret'];
              $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
              $ch = curl_init();
              curl_setopt($ch, CURLOPT_URL,$url);
              curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
              curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
              $data = curl_exec($ch);
              curl_close($ch);
              $data = json_decode($data,true);
              return $data['access_token'];
            }*/
            function set_msg($_W,$id){
                //$access_token = getaccess_token($_W);
                $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
                $user=pdo_get('zh_gjw_marketpublish',array('id'=>$id));
                $openid=pdo_get('zh_gjw_register',array('phone'=>$user['phone']));
                $formwork ='{
                    "touser": "'.$openid["openid"].'",
                    "template_id": "'.$ress["templeid"].'",
                    "form_id":"'.$user['formid'].'",
                    "data": {
                        "keyword1": {
                            "value": "'.$user['title'].'",
                            "color": "#173177"
                        },
                        "keyword2": {
                            "value":"地摊审核通过",
                            "color": "#173177"
                        }
                    }  
                }';
                $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL,$url);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
                curl_setopt($ch, CURLOPT_POST,1);
                curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
                $data = curl_exec($ch);
                curl_close($ch);
               return $data;
            }
        for ($i=0; $i <count($_GPC['id']) ; $i++) {
          $refund_order =pdo_get('zh_gjw_marketpublish',array('id'=>$_GPC['id'][$i]));  
          if ($refund_order['pay']==1) {
            echo set_msg($_W,$_GPC['id'][$i]);
            $res=pdo_update('zh_gjw_marketpublish',array('state'=>2,'shtime'=>date('Y-m-d H:i:s',time())),array('id'=>$_GPC['id'][$i]));
            // if($res){
            //   message('审核成功！', $this->createWebUrl('marketmanage'), 'success');
            // }else{
            //   message('审核失败！','','error');
            // }
          }
        }
    }
    //批量拒审地摊
    public function doMobileMarketn(){
      global $_W,$_GPC;
      include_once IA_ROOT . '/addons/zh_gjw/cert/WxPay.Api.php';
      load()->model('account');
      load()->func('communication');
      $WxPayApi = new WxPayApi();
      $input = new WxPayRefund();
      $path_cert = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_cert_' . $_W['uniacid'] . '.pem';
      $path_key = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_key_' . $_W['uniacid'] . '.pem';
                /*function getaccess_token($_W){
                  $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
                  $appid=$res['appid'];
                  $secret=$res['appsecret'];
                  $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
                  $ch = curl_init();
                  curl_setopt($ch, CURLOPT_URL,$url);
                  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
                  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
                  $data = curl_exec($ch);
                  curl_close($ch);
                  $data = json_decode($data,true);
                  return $data['access_token'];
                }*/
                function set_msg($_W,$id){
                    //$access_token = getaccess_token($_W);
                    $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
                    $user=pdo_get('zh_gjw_marketpublish',array('id'=>$id));
                    $openid=pdo_get('zh_gjw_register',array('phone'=>$user['phone']));
                    $formwork ='{
                        "touser": "'.$openid["openid"].'",
                        "template_id": "'.$ress["templeid"].'",
                        "form_id":"'.$user['formid'].'",
                        "data": {
                            "keyword1": {
                                "value": "'.$user['title'].'",
                                "color": "#173177"
                            },
                            "keyword2": {
                                "value":"地摊审核未通过",
                                "color": "#173177"
                            }
                        }  
                    }';
                    $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
                    $ch = curl_init();
                    curl_setopt($ch, CURLOPT_URL,$url);
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
                    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
                    curl_setopt($ch, CURLOPT_POST,1);
                    curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
                    $data = curl_exec($ch);
                    curl_close($ch);
                   return $data;
                }
      for ($i=0; $i <count($_GPC['id']) ; $i++) {
        $refund_order =pdo_get('zh_gjw_marketpublish',array('id'=>$_GPC['id'][$i])); 
        if (empty($refund_order['paycode'])) {
            message('发布支付未设置，所以此条未支付',$this->createWebUrl('marketmanage',array()),'success');
        } 
        $res_fee=$refund_order['payfee'];
        $marketmoney =pdo_get('zh_gjw_marketmoney',array('uniacid'=>$_W['uniacid'])); 
        // if ($refund_order['upfee']==1) {
        //   $res_fee =$res_fee+$marketmoney['upfee'];
        // }
        if ($refund_order['pay']==1) {
            // $res_fee =$res_fee+$marketmoney['publishfee'];
            if ($refund_order['paycode']) {
              $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
              $appid=$res['appid'];
              $key=$res['apikey'];
              $mchid=$res['mac_id'];
              $out_trade_no=$refund_order['paycode'];//商户订单号
              $fee = $res_fee * 100;
              $input->SetAppid($appid);
              $input->SetMch_id($mchid);
              $input->SetOp_user_id($mchid);
              $input->SetRefund_fee($fee);
              $input->SetTotal_fee($fee);
              $input->SetOut_refund_no($refund_order['paycode']);
              $input->SetOut_trade_no($out_trade_no);
              $result = $WxPayApi->refund($input, 6, $path_cert, $path_key, $key);

                
              if ($result['result_code'] == 'SUCCESS') {//退款成功
                  echo set_msg($_W,$_GPC['id'][$i]);
                  // $res=pdo_update('zh_gjw_marketpublish',array('state'=>3),array('id'=>$_GPC['id'][$i]));
                  if ($refund_order['upfee']==1) {
                    pdo_update('zh_gjw_marketpublish',array('pay'=>2,'state'=>3,'upfee'=>2),array('id'=>$_GPC['id'][$i]));
                  }else{
                    pdo_update('zh_gjw_marketpublish',array('pay'=>2,'state'=>3),array('id'=>$_GPC['id'][$i]));
                  }
              }else{
                  message($result['err_code_des'],'','error');
              }
            }
        }
      }
    }

    //批量删除订单
    public function doMobileDeleteorderlist(){
        global $_W,$_GPC;
        $res=pdo_delete("zh_gjw_orders",array('id'=>$_GPC['id']));
        if($res){
            message('删除成功！', $this->createWebUrl('orderlist'), 'success');
        }else{
            message('删除失败！','','error');
        }
    }
    //已收货时间
    public function doMobileTime(){
        global $_W, $_GPC;
        function getLevel($members, $xf_money)
        {
            for ($i = 0; $i < count($members); $i++) {
                if ($xf_money >= $members[$i]['money']) {
                    return $members[$i]['name'];
                }
                if ($xf_money < $members[$i]['money'] && $xf_money > $members[$i + 1]['money']) {
                    return $members[$i + 1]['name'];
                }
            }
        }
        $ntime=time();
        for($i=0;$i<count($_GPC['ids']);$i++){
            $times[$i]=pdo_get('zh_gjw_orders',array('id'=>$_GPC['ids'][$i]));
            $goid[$i]=$times[$i]['id'];
            if($ntime < $times[$i]['etime']){
                $retime[$i] = $times[$i]['etime']-$ntime;
                $reday[$i] = floor($retime[$i]/(60*60*24));
                $rehour[$i] = floor($retime[$i]/(60*60));
                $rehours[$i] = floor($rehour[$i]-$reday[$i]*24);
                $reminute[$i] = floor(($retime[$i] - $rehour[$i]*60*60)/60);
                $resecond[$i] = ($retime[$i] - $rehour[$i]*60*60 - $reminute[$i]*60); //剩余的秒数
            }else{
                $jieguo=pdo_update("zh_gjw_orders",array('state'=>4),array('id'=>$goid[$i]));
                if ($jieguo) {
                  
                    $cus=pdo_get('zh_gjw_orders',array('id'=>$goid[$i]));
                    $totalmoney=pdo_get('zh_gjw_orders', array('cus_id' => $cus['cus_id'], 'uniacid' => $_W['uniacid'],'state'=>4), array('sum(ofees) as total_money'));
                    $store = pdo_getall('zh_gjw_storegrade', array('uniacid' => $_W['uniacid']), array(), '', 'money DESC');
                    $storename = getLevel($store, $totalmoney['total_money']);
                    if ($storename) {
                        pdo_update('zh_gjw_cusmanage', array('level_name' => $storename), array('id' => $cus['cus_id']));
                    }
                    echo json_encode(array('msg'=>'更改成功','code'=>'201'),320);exit();
                }
                echo json_encode(array('msg'=>'失败','code'=>'202'),320);exit();
            }
        }
        echo json_encode(array('msg'=>'获取成功','code'=>'200','goid'=>$goid,'reday'=>$reday,'rehours'=>$rehours,'reminute'=>$reminute,'resecond'=>$resecond),320);exit();
        
        
    }
    //批量删除订单评论
    public function doMobileDeleteorderassess(){
        global $_W,$_GPC;
        $res=pdo_delete("zh_gjw_orderassess",array('id'=>$_GPC['id']));
        if($res){
            message('删除成功！', $this->createWebUrl('orderassess'), 'success');
        }else{
            message('删除失败！','','error');
        }
    }
  	
    //批量删除商城商品
    public function doMobileDeletestore(){
        global $_W,$_GPC;
        for ($i=0; $i <count($_GPC['id']) ; $i++) { 
          $file=pdo_get('zh_gjw_storepublish',array('id'=>$_GPC['id'][$i]));
          $imgs=explode(",",$file['img']);
          $url=str_replace('https://','',$_W['attachurl_local']);
          unlink('/www/wwwroot/'.$url.$file['video']);
          for ($j=0; $j <count($imgs) ; $j++) { 
            unlink('/www/wwwroot/'.$url.$imgs[$j]);
          }
        }
        $res=pdo_delete("zh_gjw_storepublish",array('id'=>$_GPC['id']));
        if($res){
            message('删除成功！', $this->createWebUrl('storemanage'), 'success');
        }else{
            message('删除失败！','','error');
        }
    }
    //批量审核商城商品
    public function doMobileYstore(){
        global $_W,$_GPC;
        include_once IA_ROOT . '/addons/zh_gjw/cert/WxPay.Api.php';
        load()->model('account');
        load()->func('communication');
        $WxPayApi = new WxPayApi();
        $input = new WxPayRefund();
        $path_cert = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_cert_' . $_W['uniacid'] . '.pem';
        $path_key = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_key_' . $_W['uniacid'] . '.pem';
            /*function getaccess_token($_W){
              $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
              $appid=$res['appid'];
              $secret=$res['appsecret'];
              $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
              $ch = curl_init();
              curl_setopt($ch, CURLOPT_URL,$url);
              curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
              curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
              $data = curl_exec($ch);
              curl_close($ch);
              $data = json_decode($data,true);
              return $data['access_token'];
            }*/
            function set_msg($_W,$id){
                //$access_token = getaccess_token($_W);
                $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
                $user=pdo_get('zh_gjw_storepublish',array('id'=>$id));
                $openid=pdo_get('zh_gjw_register',array('phone'=>$user['phone']));
                $formwork ='{
                    "touser": "'.$openid["openid"].'",
                    "template_id": "'.$ress["templeid"].'",
                    "form_id":"'.$user['formid'].'",
                    "data": {
                        "keyword1": {
                            "value": "'.$user['title'].'",
                            "color": "#173177"
                        },
                        "keyword2": {
                            "value":"商城商品审核通过",
                            "color": "#173177"
                        }
                    }  
                }';
                $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_URL,$url);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
                curl_setopt($ch, CURLOPT_POST,1);
                curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
                $data = curl_exec($ch);
                curl_close($ch);
               return $data;
            }
        for ($i=0; $i <count($_GPC['id']) ; $i++) {
          $refund_order =pdo_get('zh_gjw_storepublish',array('id'=>$_GPC['id'][$i]));  
          if ($refund_order['pay']==1) {
            echo set_msg($_W,$_GPC['id'][$i]);
            $res=pdo_update('zh_gjw_storepublish',array('state'=>2,'shtime'=>date('Y-m-d H:i:s',time())),array('id'=>$_GPC['id'][$i]));
            
          }
        }
    }
    //批量拒审商城商品
    public function doMobileNStore(){
      global $_W,$_GPC;
      include_once IA_ROOT . '/addons/zh_gjw/cert/WxPay.Api.php';
      load()->model('account');
      load()->func('communication');
      $WxPayApi = new WxPayApi();
      $input = new WxPayRefund();
      $path_cert = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_cert_' . $_W['uniacid'] . '.pem';
      $path_key = IA_ROOT . "/addons/zh_gjw/cert/".'apiclient_key_' . $_W['uniacid'] . '.pem';
                /*function getaccess_token($_W){
                  $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
                  $appid=$res['appid'];
                  $secret=$res['appsecret'];
                  $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$secret."";
                  $ch = curl_init();
                  curl_setopt($ch, CURLOPT_URL,$url);
                  curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
                  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
                  $data = curl_exec($ch);
                  curl_close($ch);
                  $data = json_decode($data,true);
                  return $data['access_token'];
                }*/
                function set_msg($_W,$id){
                    //$access_token = getaccess_token($_W);
                    $ress=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
                    $user=pdo_get('zh_gjw_storepublish',array('id'=>$id));
                    $openid=pdo_get('zh_gjw_register',array('phone'=>$user['phone']));
                    $formwork ='{
                        "touser": "'.$openid["openid"].'",
                        "template_id": "'.$ress["templeid"].'",
                        "form_id":"'.$user['formid'].'",
                        "data": {
                            "keyword1": {
                                "value": "'.$user['title'].'",
                                "color": "#173177"
                            },
                            "keyword2": {
                                "value":"商城商品审核未通过",
                                "color": "#173177"
                            }
                        }  
                    }';
                    $url = "https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=".$ress['accessToken']."";
                    $ch = curl_init();
                    curl_setopt($ch, CURLOPT_URL,$url);
                    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
                    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
                    curl_setopt($ch, CURLOPT_POST,1);
                    curl_setopt($ch, CURLOPT_POSTFIELDS,$formwork);
                    $data = curl_exec($ch);
                    curl_close($ch);
                   return $data;
                }
      for ($i=0; $i <count($_GPC['id']) ; $i++) {
        $refund_order =pdo_get('zh_gjw_storepublish',array('id'=>$_GPC['id'][$i])); 
        if (empty($refund_order['paycode'])) {
            message('发布支付未设置，所以此条未支付',$this->createWebUrl('storemanage',array()),'success');
        } 
        $res_fee=$refund_order['payfee'];
        $shotmoney =pdo_get('zh_gjw_storemoney',array('uniacid'=>$_W['uniacid'])); 
        
        if ($refund_order['pay']==1) {
            if ($refund_order['paycode']) {
              $res=pdo_get('zh_gjw_system',array('uniacid'=>$_W['uniacid']));
              $appid=$res['appid'];
              $key=$res['apikey'];
              $mchid=$res['mac_id'];
              $out_trade_no=$refund_order['paycode'];//商户订单号
              $fee = $res_fee * 100;
              $input->SetAppid($appid);
              $input->SetMch_id($mchid);
              $input->SetOp_user_id($mchid);
              $input->SetRefund_fee($fee);
              $input->SetTotal_fee($fee);
              $input->SetOut_refund_no($refund_order['paycode']);
              $input->SetOut_trade_no($out_trade_no);
              $result = $WxPayApi->refund($input, 6, $path_cert, $path_key, $key);

              if ($result['result_code'] == 'SUCCESS') {//退款成功
                
                echo set_msg($_W,$_GPC['id'][$i]);
                if ($refund_order['upfee']==1) {
                  pdo_update('zh_gjw_storepublish',array('pay'=>2,'state'=>3,'upfee'=>2),array('id'=>$_GPC['id'][$i]));
                }else{
                  pdo_update('zh_gjw_storepublish',array('pay'=>2,'state'=>3),array('id'=>$_GPC['id'][$i]));
                }
                  
              }else{
                  message($result['err_code_des'],'','error');
              }
            }
        }
      }
    }
  	//批量删除商家信誉
    public function doMobileDeleterepurecord(){
        global $_W,$_GPC;
        $res=pdo_delete("zh_gjw_reputationrecord",array('id'=>$_GPC['id']));
        if($res){
            message('删除成功！', $this->createWebUrl('reputationrecords'), 'success');
        }else{
            message('删除失败！','','error');
        }
    }
  	
  	//批量删除商家信誉消费
    public function doMobileDeleterepucosts(){
        global $_W,$_GPC;
        $res=pdo_delete("zh_gjw_repucost",array('id'=>$_GPC['id']));
        if($res){
            message('删除成功！', $this->createWebUrl('repucosts'), 'success');
        }else{
            message('删除失败！','','error');
        }
    }
}